set more 1
clear

pause off 

capture log close


global dir_tab_out     "../outputs"
global dir_work_out    "out_figs" 


global educTarget  hgc13more



******************************************************************
* Table 6 Panel A
******************************************************************


global  dir_basedata     "out_files"
global  dir_cfdata1       "out_files_CFnoDq" 
global  dir_cfdata2       "out_files_optTax" 

local educTarget $educTarget

use $dir_cfdata1/sim_model_part1, clear
gen hgc13more = (educ>=13)

rename * cf1_*
rename cf1_id  id 
rename cf1_age age

save tempdata, replace 

use $dir_cfdata2/sim_model_part1, clear
gen hgc13more = (educ>=13)

rename * cf2_*
rename cf2_id  id 
rename cf2_age age


merge 1:1 id age using tempdata
keep if _merge == 3
!rm tempdata.dta  
drop _merge


merge 1:1 id age using $dir_basedata/sim_model_part1 
gen hgc13more = (educ>=13)
keep if _merge == 3
drop _merge


	sort id age
	foreach var of varlist addiction dq {
	foreach a in 30 {
		gen `var'_a`a'_ = `var' if age == `a'
		by id: egen `var'_a`a' = max(`var'_a`a'_)
		drop `var'_a`a'_
	}
	}

	foreach a in 30 {
	by id: gen everdq_a`a' = (addiction_a`a' + dq_a`a' > 0)  
	label var everdq_a`a' "Ever Smoker at age `a' (Benchmark Case)"
	label values everdq_a`a' everdq
	
	}
	
	capture matrix drop mat_`educTarget'
	
	tabstat `educTarget' cf1_`educTarget' cf2_`educTarget' if age == 30 & everdq_a30== 1 & hgc13more==0, stat(mean) save

	matrix mat_`educTarget' = [r(StatTotal)]

	tabstat `educTarget' cf1_`educTarget' cf2_`educTarget'  if age == 30 & everdq_a30== 1 , stat(mean) save

	matrix mat_`educTarget'   = [nullmat(mat_`educTarget') \ r(StatTotal) ]

	tabstat `educTarget' cf1_`educTarget' cf2_`educTarget' if age == 30, stat(mean) save

	matrix mat_`educTarget'   = [nullmat(mat_`educTarget' ) \ r(StatTotal) ]

	matrix list mat_`educTarget'


	
	** Table 6 Panel A
	matrix colnames mat_`educTarget' = "Benchmark""No_Smoking""Excise_Tax"
	matrix rownames mat_`educTarget' = "Non-college_smokers""Benchmark_ever_smokers""All_youths"
	
	outtable using $dir_work_out/stats_`educTarget',         mat(mat_`educTarget') replace          nobox center caption("College attendance rates in different simulations") f(%100.3f) clabel(stats_`educTarget') 
	outtable using $dir_tab_out/Table_06_panelA,         mat(mat_`educTarget') replace          nobox center caption("College attendance rates in different simulations") f(%100.3f) clabel(stats_`educTarget') 
	

******************************************************************
* Table 6 Panel B
******************************************************************

* Benchmark model 
global  dir_data    "out_files"

use $dir_data/sim_model_part1, clear
gen hgc13more = (educ>=13)
keep if age == 30 
probit hgc13more thetac thetan parents_clg 
local my_r2_p = e(r2_p) 
margins, dydx(  thetac thetan parents_clg  ) atmeans post
estadd scalar my_r2_p = `my_r2_p', replace	
	
eststo allregcf1_probit	


* No smoking
global  dir_data    "out_files_CFnoDq"

use $dir_data/sim_model_part1, clear
gen hgc13more = (educ>=13)
keep if age == 30 
probit hgc13more thetac thetan parents_clg 
local my_r2_p = e(r2_p) 
margins, dydx(  thetac thetan parents_clg  ) atmeans post
estadd scalar my_r2_p = `my_r2_p', replace	
	
eststo allregcf2_probit	


* CF: Revenue neutral excise tax
global  dir_data    "out_files_optTax"

use $dir_data/sim_model_part1, clear
gen hgc13more = (educ>=13)
keep if age == 30 
probit hgc13more thetac thetan parents_clg 
local my_r2_p = e(r2_p) 
margins, dydx(  thetac thetan parents_clg  ) atmeans post
estadd scalar my_r2_p = `my_r2_p', replace	
	
eststo allregcf3_probit	


	** Table 6 Panel B
	quietly esttab allregcf1_probit allregcf2_probit allregcf3_probit	 using $dir_work_out/cfregall_hgc13more_probit.tex,       replace stats(N my_r2_p, fmt(%9.0fc %9.3f) labels("Observations""Pseudo R2"))  b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) label title(College attendance regression\label{cfreg:chghgc13} ) nogaps compress `option' nomtitles
	quietly esttab allregcf1_probit allregcf2_probit allregcf3_probit	 using $dir_tab_out/Table_06_panelB.tex,       replace stats(N my_r2_p, fmt(%9.0fc %9.3f) labels("Observations""Pseudo R2"))  b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) label title(College attendance regression\label{cfreg:chghgc13} ) nogaps compress `option' nomtitles



